// 预览图片加载-------------------------------------------------------------------------
let headSculptureFileInput = document.getElementById('headSculptureFile');
let info = document.getElementById('info');
let preview = document.getElementById('imagePreview');
// 监听change事件:
headSculptureFileInput.addEventListener('change', function () {
    // 清除背景图片:
    preview.style.backgroundImage = '';
    if (!headSculptureFileInput.value) {
        info.innerHTML = '没有选择文件';
        return;
    }
    let file = headSculptureFileInput.files[0];
    let size = file.size;
    if (size >= 50 * 1024 * 1024) {
        alert('文件大小超出限制');
        info.innerHTML = '文件大小超出限制';
        return false;
    }
    // 获取File信息:
    info.innerHTML = `文件名称:  + ${file.name}<br>
                                    文件大小: ${file.size} <br>
                                    上传时间: ${file.lastModifiedDate}
                                    `;
    if (!['image/jpeg', 'image/png', 'image/gif'].includes(file.type)) {
        alert('不是有效的图片文件!');
        return;
    }
    // 读取文件:
    let reader = new FileReader();
    reader.onload = function (e) {
        let data = e.target.result;
        preview.src = data
    };
    // 以DataURL的形式读取文件:
    reader.readAsDataURL(file);

});

// 检验是否为空--------------------------------------------------------------------------
function checkCreateUser() {
    let headSculptureFileInput = document.getElementById('headSculptureFile');
    let headSculptureFileInputValue = headSculptureFileInput.value;
    let usernameInput = document.getElementById('username');
    let usernameInputValue = usernameInput.value;
    let passwordInput = document.getElementById('password');
    let passwordInputValue = passwordInput.value;
    let nicknameInput = document.getElementById('nickname');
    let nicknameInputValue = nicknameInput.value;
    let phoneInput = document.getElementById('phone');
    let phoneInputValue = phoneInput.value;
    let personalIntroductionInput = document.getElementById('personalIntroduction');
    let personalIntroductionInputValue = personalIntroductionInput.value;
    if ('' == headSculptureFileInputValue) {
        alert('未上传头像!')
        return false;
    }
    if ('' == usernameInputValue) {
        alert('未填写用户名!')
        return false;
    }
    if ('' == passwordInputValue) {
        alert('未填写密码!')
        return false;
    }
    if ('' == nicknameInputValue) {
        alert('未填写昵称!')
        return false;
    }
    if ('' == phoneInputValue) {
        alert('未填写手机号!')
        return false;
    }
    if ('' == personalIntroductionInputValue) {
        alert('未填写个人介绍!')
        return false;
    }
    return true;
}
// 图片裁切----------------------------------------------------------------------------
// import 'cropperjs/dist/cropper.css';
// import Cropper from 'cropperjs';
// function cropImage(){
//     const cropper = new Cropper(preview, {
//         viewMode:1,
//         // 宽高比
//         aspectRatio: 1 / 1,
//         crop(event) {
//             // console.log(event.detail.x);
//             // console.log(event.detail.y);
//             // console.log(event.detail.width);
//             // console.log(event.detail.height);
//             // console.log(event.detail.rotate);
//             // console.log(event.detail.scaleX);
//             // console.log(event.detail.scaleY);
//         }
//     });
//     console.log(cropper);
// }









